﻿using System;
using System.Windows;
using WPFTestSolution.Utils;

namespace WPFTestSolution {
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App {
        protected override void OnStartup(StartupEventArgs e) {
            if (false && !DotNetInstallCheckUtils.IsDotNetInstalled()) {
                var result = MessageBox.Show(
                    "需要安装 .NET 8 运行时才能运行此程序，是否立即下载？",
                    "缺少运行时",
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Warning);
        
                if (result == MessageBoxResult.Yes) {
                    DotNetInstallCheckUtils.Go2DotNet8();
                }
                Application.Current.Shutdown();
            }
            
            #if DEBUG
                // 仅调试时显示控制台
                //Console2WindowUtils.AllocConsole(); 
                Console.WriteLine("if DEBUG");
            // #else
            #endif

            base.OnStartup(e);

            Console.WriteLine("OnStartup0");

            System.Diagnostics.Trace.WriteLine("OnStartup2");
            System.Diagnostics.Debug.WriteLine("OnStartup3");

            // Console.SetOut(new TraceTextWriter());

            //https://www.bilibili.com/video/BV1bV411A7Eq
            Console.WriteLine("1.OnStartup 被执行"); //加载本地数据
        }

        protected override void OnActivated(EventArgs e) {
            base.OnActivated(e);
            Console.WriteLine("2.OnActivated 被执行");
        }

        protected override void OnDeactivated(EventArgs e) {
            base.OnDeactivated(e);
            Console.WriteLine("3.OnDeactivated 被执行");
        }

        protected override void OnExit(ExitEventArgs e) {
            base.OnExit(e);
            Console.WriteLine("4.OnExit 被执行"); //保存数据
        }
    }
}